package com.lai.note.activity;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentTransaction;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import com.lai.note.R;
import com.lai.note.adapter.MyFragmentStateAdapter;
import com.lai.note.fragment.PersonFragment;
import com.lai.note.fragment.RandomWenanFragment;
import com.lai.note.fragment.RecordsNoteFragment;
import com.lai.note.fragment.RecordsWenanFragment;
import com.lai.note.fragment.WriteNoteFragment;
import com.lai.note.fragment.WriteWenanFragment;


public class MainActivity extends AppCompatActivity{


    private ViewPager2 viewPager;
    private MenuItem menuItem;
    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewPager = (ViewPager2) findViewById(R.id.mViewPager);
        bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_nav_view);

        //bottomNavigationView绑定
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                switch(menuItem.getItemId()){
                    case R.id.random_wenan:
                        viewPager.setCurrentItem(0);
                        break;
                    case R.id.write_wenan:
                        viewPager.setCurrentItem(1);
                        break;
                    case R.id.write_note:
                        viewPager.setCurrentItem(2);
                        break;
                    case R.id.me:
                        viewPager.setCurrentItem(3);
                        break;
                }
                return false;
            }
        });

        //ViewPager2绑定
        viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                menuItem = bottomNavigationView.getMenu().getItem(position);
                menuItem.setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
        setupViewPager(viewPager);

        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.random_wenan,R.id.write_wenan,R.id.write_note,R.id.me
        ).build();

    }

    private void setupViewPager(ViewPager2 viewPager){
        RecyclerView.Adapter adapter = new RecyclerView.Adapter() {
            @NonNull
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                return null;
            }

            @Override
            public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

            }

            @Override
            public int getItemCount() {
                return 0;
            }
        };
        viewPager.setAdapter(new MyFragmentStateAdapter(this));
    }


}

